package com.example.demo.web.sessionfilter;

import com.example.demo.web.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author wangsl
 * @date 2020/6/20 22:39
 * <p>
 * Description:
 */
@Controller
@RestController
public class LoginController {

    @RequestMapping("login")
    public String login(String name, String pwd, HttpServletRequest request) {
        HttpSession session = request.getSession();
        if ("root".equals(name) && "root".equals(pwd)) {
            User user = new User();
            user.setName(name);
            session.setAttribute("user", user);
            return "登录成功";
        } else {
            return "用户名或密码错误!";
        }
    }
}
